package com.czh.springboot04.MyController;

import com.czh.springboot04.entity.UserMark;
import com.czh.springboot04.service.UserMarkService;
import com.czh.springboot04.service.serviceimpl.UserMarkServiceImpl;
import com.czh.springboot04.util.R;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.sql.DataSource;
import java.util.List;


@CrossOrigin
@RestController
@RequestMapping("/UserMarkController")
public class UserMarkController {
    @Autowired
    DataSource dataSource;
    @Autowired
    UserMarkService userMarkService = new UserMarkServiceImpl();
    @PostMapping("/insertUserMark")
    public R insertUserMark(@RequestBody UserMark userMark) {
        int i = userMarkService.insertUserMark(userMark);
        if(i!=0){
            return R.ok("添加成功！");
        }else{
            return R.fail("添加失败！");
        }
    }
    @PutMapping("/updateUserMarkById")
    public R updateUserMarkById(@RequestBody UserMark userMark) {
        int i = userMarkService.updateUserMarkById(userMark);
        if(i!=0){
            return R.ok("修改成功！");
        }else{
            return R.fail("修改失败！");
        }
    }
    @GetMapping("/selectUserMarkById")
    public R selectUserMarkById(Integer id) {
        UserMark userMark = userMarkService.selectUserMarkById(id);
        if(userMark!=null){
            return R.ok(userMark);
        }else{
            return R.fail("查询失败！");
        }
    }
    @DeleteMapping("/deleteUserMarkById/{id}")
    public R deleteUserMarkById(@PathVariable("id") Integer id) {
        int i = userMarkService.deleteUserMarkById(id);
        if(i!=0){
            return R.ok("删除成功！");
        }else{
            return R.fail("删除失败！");
        }
    }
    @DeleteMapping("/deleteUserMarkByList")
    public R deleteUserMarkByList(@RequestBody List<Integer> idList) {
        int i = userMarkService.deleteUserMarkByList(idList);
        if(i!=0){
            return R.ok("删除成功！");
        }else{
            return R.fail("删除失败！");
        }
    }
    @GetMapping("/selectUserMarkAll")
    public R selectUserMarkAll(Integer userId, Integer consultId, Integer appId, Integer markStar,@RequestParam(required = false, defaultValue = "1") Integer pageNum,@RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        PageInfo<UserMark> userMarkPageInfo = userMarkService.selectUserMarkAll(userId, consultId, appId, markStar, pageNum, pageSize);
        if(userMarkPageInfo!=null){
            return R.ok(userMarkPageInfo);
        }else {
            return R.fail("查询失败！");
        }
    }
    @GetMapping("/selectUserMark")
    public R selectUserMark() {
        List<UserMark> userMarkList = userMarkService.selectUserMark();
        if(userMarkList!=null){
            return R.ok(userMarkList);
        }else {
            return R.fail("查询失败！");
        }
    }
}
